{{extend 'layout.html'}}
{{
check,t0=True,today.hour*60+today.minute
def format_time(t,cc=False,ct=[check,t0]):
   h=t/60
   m=t-h*60
   t1='%i:%.2i'%(h,m)
   if h>11 and h<24:
       t1=t1+'pm'
   else:
       t1=t1+'am'   
       pass
   if cc and ct[0] and t>ct[1]: ct[0],t1=False,TAG.BLINK(B(t1))
   return t1
}}
<h2>{{=T('Next Train')}}</h2>

<img src="/{{=request.application}}/static/metra.gif" width="200px"/>

<h3><a href="{{=URL(r=request,f='tiny')}}">try the compact display</a><h3>
{{=form}}
<br/><br/>

{{if len(trains):}}
<blink>{{=T('Next train flashing')}}</blink>
<h2>{{=T('Timetable')}}</h2>
[<a href="{{=URL(r=request,vars=dict(arrival=session.vars.departure,departure=session.vars.arrival,when=session.vars.when))}}">return trains</a>]
<table class="sortable" id="sortable_table">
<thead>
<tr>
    <td>{{=T('Line')}}</td>
    <td>{{=T('Train Number')}}</td>
    <td>{{=T('Time')}}</td>
    <td>{{=T('Departure')}}</td>
    <td>{{=T('Time')}}</td>
    <td>{{=T('Arrival')}}</td>
    <td>{{=T('Duration (min)')}}</td>
</tr>   
</thead>
<tbody>
{{for train in trains:}}
<tr>
<td><a href="http://www.google.com/search?hl=en&q=Metra+{{=lines[train.departure.line]}}&btnI">{{=lines[train.departure.line]}}</a></td>
<td style="text-align: right"><a href="{{=URL(r=request,f='train',args=[request.vars.when,train.departure.number])}}">{{=train.departure.number}}</a></td>
<td style="text-align: right">{{=format_time(train.departure.time,True)}}</td>
<td><a href="{{=URL(r=request,f='station',args=[train.departure.station])}}">{{=stations[train.departure.station]}}</a></td>
<td style="text-align: right">{{=format_time(train.arrival.time)}}</td>
<td><a href="{{=URL(r=request,f='station',args=[train.arrival.station])}}">{{=stations[train.arrival.station]}}</a></td>
<td style="text-align: right">{{=train.arrival.time-train.departure.time}}</td>
</tr>
{{pass}}
</tbody>
</table>
{{pass}}
